//
//  AppsSessionManager.m
//  ToHow
//
//  Created by maple on 14-5-6.
//  Copyright (c) 2014 sinosoft. All rights reserved.
//

#import "AppSessionManager.h"

static AppSessionManager *defaultManager;

@implementation AppSessionManager

+ (id)sharedManager {
    @synchronized(@"AppSessionManager"){
        if(!defaultManager){
            defaultManager = [[self alloc] init];
        }
    }
    return defaultManager;
}


- (void)setCurrentUser:(NSString *)currentUser{
    [[AppLocalManager sharedManager] saveData:currentUser andKey:CURRENT_USER];
}

- (NSString *)getCurrentUser{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_USER];
}

- (void)setCurrentPassword:(NSString *)password {
    [[AppLocalManager sharedManager] saveData:password andKey:CURRENT_PASSWORD];
}

- (NSString *)getCurrentUserPassword {
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_PASSWORD];
}

- (void)setCurrentMemberId:(NSString *)currentMemberId {
    [[AppLocalManager sharedManager] saveData:currentMemberId andKey:CURRENT_MEMBER_ID];
}

- (NSString *)getCurrentMemberId {
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_MEMBER_ID];
}

- (void)setCurrentPersonalStoreId:(NSString *)currentPersonalStoreId{
    [[AppLocalManager sharedManager] saveData:currentPersonalStoreId andKey:CURRENT_PERSONALSTOREID];
}
- (NSString *)getCurrentPersonalStoreId{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_PERSONALSTOREID];
}

- (void)setCurrentToken:(NSString *)token{
    [[AppLocalManager sharedManager] saveData:token andKey:CURRENT_TOKEN];
}

- (NSString *)getCurrentToken{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_TOKEN];
}



- (void)setCurrentBalance:(NSNumber *)balance{
    [[AppLocalManager sharedManager] saveData:balance andKey:CURRENT_BALANCE];
}

- (NSNumber *)getCurrentBalance{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_BALANCE];
}

- (void)setCurrentShoppingCartCount:(NSNumber *)count{
    [[AppLocalManager sharedManager] saveData:count andKey:CURRENT_SHOPPING_CART_COUNT];

}

- (NSNumber *)getCurrentShoppingCartCount{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_SHOPPING_CART_COUNT];
}

- (BOOL)isLaunched{
    BOOL isLaunched = [[[AppLocalManager sharedManager] getDataByKey:IS_LAUNCHED] boolValue];
    return isLaunched;
}

- (void)setLaunched:(BOOL)launched{
    [[AppLocalManager sharedManager] saveData:[NSNumber numberWithBool:launched] andKey:IS_LAUNCHED];
}

- (BOOL)isLogin {
    NSString *memberId = [self getCurrentMemberId];
    BOOL login = [[[AppLocalManager sharedManager] getDataByKey:[NSString stringWithFormat:@"%@:login",memberId]] boolValue];
    return login;
}

- (void)setLogin:(NSString *)user memberId:(NSString *)memberId password:(NSString *)password login:(BOOL)login {
    [self setCurrentUser:user];
    [self setCurrentPassword:password];
    [self setCurrentMemberId:memberId];
    [[AppLocalManager sharedManager] saveData:[NSNumber numberWithBool:login] andKey:[NSString stringWithFormat:@"%@:login",memberId]];
}

- (void)setLogin:(NSString *)user memberId:(NSString *)memberId email:(NSString *)email password:(NSString *)password login:(BOOL)login {
    [self setCurrentUser:user];
    [self setCurrentPassword:password];
    [self setCurrentMemberId:memberId];
    [self setCurrentEmail:email];
    [[AppLocalManager sharedManager] saveData:[NSNumber numberWithBool:login] andKey:[NSString stringWithFormat:@"%@:login",memberId]];
}

- (void)setLogin:(NSString *)user memberId:(NSString *)memberId email:(NSString *)email password:(NSString *)password login:(BOOL)login mobile:(NSString *)mobile sex:(NSNumber *)sex nickName:(NSString *)nickName pic:(NSString *)pic{
    [self setCurrentUser:user];
    [self setCurrentPassword:password];
    [self setCurrentMemberId:memberId];
    [self setCurrentEmail:email];
    [self setCurrentMobile:mobile];
    [self setCurrentSex:sex];
    [self setCurrentNibName:nickName];
    [self setCurrentUserImageUrlStr:pic];
    [[AppLocalManager sharedManager] saveData:[NSNumber numberWithBool:login] andKey:[NSString stringWithFormat:@"%@:login",memberId]];
}

- (void)setLogin:(NSString *)user memberId:(NSString *)memberId login:(BOOL)login {
    [self setCurrentUser:user];
    [self setCurrentMemberId:memberId];
    [[AppLocalManager sharedManager] saveData:[NSNumber numberWithBool:login] andKey:[NSString stringWithFormat:@"%@:login",memberId]];
}

- (void)setLogin:(BOOL)login{
    [[AppLocalManager sharedManager] saveData:[NSNumber numberWithBool:login] andKey:[NSString stringWithFormat:@"%@:login",[self getCurrentMemberId]]];
}

- (void)setCurrentNibName:(NSString *)nibName{
    [[AppLocalManager sharedManager] saveData:nibName andKey:CURRENT_NIBNAME];
}
- (NSString *)getCurrentNibName{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_NIBNAME];
}

- (void)setCurrentEmail:(NSString *)email{
    [[AppLocalManager sharedManager] saveData:email andKey:CURRENT_EMAIL];
}
- (NSString *)getCurrentEmail{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_EMAIL];
}

- (void)setCurrentUserImageUrlStr:(NSString *)userImageUrlStr{
    [[AppLocalManager sharedManager] saveData:userImageUrlStr andKey:CURRENT_USER_IMAGE_URLSTR];
}

- (NSString *)getCurrentUserImageUrlStr{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_USER_IMAGE_URLSTR];
}

- (void)setCurrentSex:(NSNumber *)sex{
    [[AppLocalManager sharedManager] saveData:sex andKey:CURRENT_SEX];
}
- (NSNumber *)getCurrentSex{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_SEX];
}

- (void)setCurrentMobile:(NSString *)mobile{
    [[AppLocalManager sharedManager] saveData:mobile andKey:CURRENT_MOBILE];
}
- (NSString *)getCurrentMobile{
    return [[AppLocalManager sharedManager] getDataByKey:CURRENT_MOBILE];
}




@end
